package demo1;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-03-10
 * Time: 22:57
 */
public class FileDemo1 {
    public static void main(String[] args) throws IOException {
        //相对路径
        File file1 = new File(".\\aaa\\bbb\\ccc");
        //绝对路径
        File file2 = new File("D:\\a.text");
        //
        //判断文件是否存在
        System.out.println("file1.exists = " + file1.exists());
        System.out.println("file2.exists = " + file2.exists());
        System.out.println("=====================================================================");
        //获取文件名
        System.out.println("file1.getName = " + file1.getName());
        System.out.println("file2.getName = " + file2.getName());
        System.out.println("=====================================================================");
        //获取当前路径下所有目录/文件名
        System.out.println("file1.list = " + Arrays.toString(file1.list()));
        System.out.println("file2.list = " + Arrays.toString(file2.list()));
        System.out.println("=====================================================================");
        //获取当前路径下所有目录/文件的对象
        System.out.println("file1.listFiles = " + Arrays.toString(file1.listFiles()));
        System.out.println("file2.listFiles = " + Arrays.toString(file2.listFiles()));
        System.out.println("=====================================================================");
        //获取相对路径
        System.out.println("file1.getPath = " + file1.getPath());
        System.out.println("file2.getPath = " + file2.getPath());
        System.out.println("=====================================================================");
        //获取父路径
        System.out.println("file1.getParent = " + file1.getParent());
        System.out.println("file2.getParent = " + file2.getParent());
        System.out.println("=====================================================================");
        //获取完全路径
        System.out.println("file1.getAbsolutePath = " + file1.getAbsolutePath());
        System.out.println("file2.getAbsolutePath = " + file2.getAbsolutePath());
        System.out.println("=====================================================================");
        //获取优化后的完全路径
        System.out.println("file1.getCanonicalPath = " + file1.getCanonicalPath());
        System.out.println("file2.getCanonicalPath = " + file2.getCanonicalPath());
        System.out.println("=====================================================================");
        //创建文件
        System.out.println("file1.createNewFile = " + file1.createNewFile());
        System.out.println("file2.createNewFile = " + file2.createNewFile());
        System.out.println("=====================================================================");
        //不为空的文件夹删不动
        System.out.println("file1.delete = " + file1.delete());
        System.out.println("file2.delete = " + file2.delete());
        System.out.println("=====================================================================");
    }
}
